package com.heima.wemedia.feign;

import com.heima.client.article.IArticleClient;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.pojos.wemedia.WmChannel;
import com.heima.model.common.pojos.wemedia.WmSensitive;
import com.heima.wemedia.mapper.WmSensitiveMapper;
import com.heima.wemedia.service.BaiduScanService;
import com.heima.wemedia.service.WmChannelService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
@Api(tags = "频道管理")
public class AdWemediaController{

    @Autowired
    private WmChannelService wmChannelService;


    @Autowired
    private BaiduScanService baiduScanService;

    @Autowired
    private WmSensitiveMapper wmSensitiveMapper;

    /**
     * 添加频道 因为直接写在了WmChannelServiceImpl类中 无需远程调用
     */
  /*  @PostMapping("/api/v1/channel/save")
    public ResponseResult save(@RequestBody AdChannelDto adChannelDto) {
        log.info("添加频道:{}", adChannelDto);
        return wmChannelService.saveChannel(adChannelDto);
    }*/

    // 查询所有频道
    @GetMapping("/api/v1/channel/channels")
    public ResponseResult channels() {
        log.info("加载所有频道");
        List<WmChannel> list = wmChannelService.list();
        return ResponseResult.okResult(list);
    }
    /**
     * 远程调用百度敏感词文本审核
     * @param text
     * @return
     */
    @GetMapping("/api/v1/baidu/scantext")
    public ResponseResult scanText(@RequestParam String text) {
        //1、日志
        log.info("远程调用百度敏感词文本审核：{}", text);
        Integer conclusionType = baiduScanService.scanText(text);
        //2、调用service进行文本审核
        return ResponseResult.okResult(conclusionType);
    }

    /**
     * 远程调用本地敏感词文本审核
     * @return
     */
    @GetMapping("/api/v1/sensitive/autoscan")
    public List<WmSensitive> autoScan() {
        log.info("远程调用本地敏感词文本审核：{}");

        return wmSensitiveMapper.selectList(null);
    }


}
